/* Copyright (c) 2021-2025 Qualcomm Technologies International, Ltd. */
/* %%version */


#include "vcp_common.h"
#include "vcp_debug.h"


#ifndef EXCLUDE_CSR_BT_VOCS_CLIENT_MODULE
/***************************************************************************/
void vocsInitQueueInst(CsrCmnListElm_t *elem)
{
    vcpVocsServiceQueueElement *incElement = (vcpVocsServiceQueueElement *)elem;

    incElement->cid = 0x00;
    incElement->service_handle = INVALID_PROFILE_HANDLE;

    memset(&incElement->device_data, 0x00, sizeof(GattVocsClientDeviceData));
}

/***************************************************************************/
void vocsDeInitQueueInst(CsrCmnListElm_t *elem)
{
    vcpVocsServiceQueueElement *incElement = (vcpVocsServiceQueueElement *)elem;

    incElement->cid = 0x00;
    incElement->service_handle = INVALID_PROFILE_HANDLE;

    memset(&incElement->device_data, 0x00, sizeof(GattVocsClientDeviceData));
}

/****************************************************************************/
bool vcpIsValidVocsInst(VCP *vcp_inst, ServiceHandle srvc_hndl)
{
    vcpVocsServiceQueueElement *ptr = (vcpVocsServiceQueueElement*)vcp_inst->vocs_service_queue.first;
    while(ptr)
    {
        if (ptr->service_handle == srvc_hndl)
        {
            return TRUE;
        }

        ptr = ptr->next;
    }
    return FALSE;
}
#endif

#ifndef EXCLUDE_CSR_BT_AICS_CLIENT_MODULE
/***************************************************************************/
void aicsInitQueueInst(CsrCmnListElm_t *elem)
{
    vcpAicsServiceQueueElement *incElement = (vcpAicsServiceQueueElement *)elem;

    incElement->cid = 0x00;
    incElement->service_handle = 0x00;

    memset(&incElement->device_data, 0x00, sizeof(GattAicsClientDeviceData));
}

/***************************************************************************/
void aicsDeInitQueueInst(CsrCmnListElm_t *elem)
{
    vcpAicsServiceQueueElement *incElement = (vcpAicsServiceQueueElement *)elem;

    incElement->cid = 0x00;
    incElement->service_handle = 0x00;

    memset(&incElement->device_data, 0x00, sizeof(GattAicsClientDeviceData));
}

/****************************************************************************/
bool vcpIsValidAicsInst(VCP *vcp_inst, ServiceHandle srvc_hndl)
{
    vcpAicsServiceQueueElement* ptr = (vcpAicsServiceQueueElement*)vcp_inst->aics_service_queue.first;

    while(ptr)
    {
        if (ptr->service_handle == srvc_hndl)
        {
            return TRUE;
        }

        ptr = ptr->next;
    }
    return FALSE;
}
#endif

/******************************************************************************************/
GattVcsClientDeviceData *VcpGetAttributeHandles(VcpProfileHandle profileHandle)
{
    VCP *vcpInst = ServiceHandleGetInstanceData((ServiceHandle) profileHandle);

    if (vcpInst)
    {
        return GattVcsClientGetHandlesReq(vcpInst->vcs_srvc_hdl);
    }

    return NULL;
}

/******************************************************************************************/
CsrBool vcpInstFindBySrvcHndl(CsrCmnListElm_t *elem, void *data)
{
    ProfileHandleListElm_t *profile_hndl_elm = (ProfileHandleListElm_t *)elem;
    ServiceHandle profile_handle = *(ServiceHandle *)data;

    return (profile_hndl_elm->profile_handle == profile_handle);
}

/******************************************************************************************/
CsrBool vcpProfileHndlFindByBtConnId(CsrCmnListElm_t *elem, void *data)
{
    ProfileHandleListElm_t *profile_hndl_elm = (ProfileHandleListElm_t *)elem;
    CsrBtConnId     btConnId   = *(CsrBtConnId *) data;
    VCP *vcp_inst = FIND_VCP_INST_BY_PROFILE_HANDLE(profile_hndl_elm->profile_handle);

    if(vcp_inst)
    {
        return (vcp_inst->cid == btConnId);
    }

    return FALSE;
}

/******************************************************************************************/
CsrBool vcpProfileHndlFindByVcsSrvcHndl(CsrCmnListElm_t *elem, void *data)
{
    ProfileHandleListElm_t *profile_hndl_elm = (ProfileHandleListElm_t *)elem;
    ServiceHandle vcs_srvc_hndl = *(ServiceHandle *)data;
    VCP *vcp_inst = FIND_VCP_INST_BY_PROFILE_HANDLE(profile_hndl_elm->profile_handle);

    if(vcp_inst)
    {
         return (vcp_inst->vcs_srvc_hdl == vcs_srvc_hndl);
    }

    return FALSE;
}

/******************************************************************************************/
CsrBool vcpProfileHndlFindByVocsSrvcHndl(CsrCmnListElm_t* elem, void* data)
{
    ProfileHandleListElm_t *profile_hndl_elm = (ProfileHandleListElm_t*)elem;
    ServiceHandle vocs_srvc_hndl = *(ServiceHandle*)data;
    VCP *vcp_inst = FIND_VCP_INST_BY_PROFILE_HANDLE(profile_hndl_elm->profile_handle);

    if (vcp_inst)
    {
        vcpVocsServiceQueueElement* ptr = (vcpVocsServiceQueueElement*)vcp_inst->vocs_service_queue.first;
        while (ptr)
        {
            if (ptr->service_handle == vocs_srvc_hndl)
            {
                return TRUE;
            }
            ptr = ptr->next;
        }
    }
    return FALSE;
}

CsrBool vcpProfileHndlFindByAicsSrvcHndl(CsrCmnListElm_t* elem, void* data)
{
    ProfileHandleListElm_t *profile_hndl_elm = (ProfileHandleListElm_t*)elem;
    ServiceHandle aics_srvc_hndl = *(ServiceHandle*)data;
    VCP *vcp_inst = FIND_VCP_INST_BY_PROFILE_HANDLE(profile_hndl_elm->profile_handle);

    if (vcp_inst)
    {
        vcpAicsServiceQueueElement *ptr = (vcpAicsServiceQueueElement*)vcp_inst->aics_service_queue.first;
        while (ptr)
        {
            if (ptr->service_handle == aics_srvc_hndl)
            {
                return TRUE;
            }
            ptr = ptr->next;
        }
    }
    return FALSE;
}
